package q441_arrangeCoins;

public class Solution_2 {

    public int arrangeCoins(int n){
        long l = 1, r = n;
        while (r - l > 1) {
            long mid = (l + r) / 2;
            if ((long) mid * (mid + 1) >  (long) 2 * n) {
                r = (long)(l + r) / 2;
            } else {
                l = (long)(l + r) / 2;
            }

        }
        return (int) ((int) r * r <= n ? r : l);
    }
}
